refactored to promises for tests and db code