Move all database logic to its own class