Moved interval logic to db lib

Also added TODO, renamed db.js var