Moved SQL to the controller