optimizing code, reducing db calls