database refactor using promises