reorganize DB and refactor API around promises