manual sorting query fix