Add database, restructure and add some tests