Changed error handler to check by constants instead of magic numbers