Separated code and implemented error message