formatted errors, factored code