Fixed some missing code and changed the error messages