Adding database logic