make db a param in creating app to support different dbs

this way level-test works, another app can use a bunch of API apps with the same db, later we can use level.js in the browser, etc.

i also moved some code around into sections, let me know if anything is not okay.