refactoring + extra exceptions for readability