auto-create DB on start & refactor code

Add auto-create DB on start (if not exists),
and big refactor the code (db works mainly)