Improve initialization and error detection during allocation for ks_problem_t