refactored, added in error messages