initial rewrite: added database support