Improves code and error message