Moved SQL with basic retrieval queries into models.