moving reset_db to function and some cleanup