Added all database logic