refactoring: use exceptions instead of returns