Refactored error handling in keymat_v1_t