Fewer sql queries