refactors to avoid n+1 query