add error messages, refactoring