Simplify error checks and increase test coverage