Extract duplicate context query from controller