reorg and add insert into db
added insert function and cleaned up init_database