Changed the code to do less db requests send less traffic