Refactor err() and fail() functions into clearer error() function