Fix N+1 problem