db errors handling
minor refactoring