forked by hama_db, to clean up code