small refactorings, added custom error messages