Fewer sql queries

Good point, I'll update this.