make db::run argument handler more robust
organize some functions