Reduce number of db queries