Refactors data access to make template simpler