Some refactoring, and started using sql joins for retrieving associations.