solve n+1 query problem