some more refactoring, added exceptions