Refactoring database, exception and assertion flows