Add exception factory methods and additional refactoring