remove panic and return error