Refactoring work with database.