Cleanup of SQL Code

Removing SQL Queries and replacing with ORM code.