database logic implemented