fix index bug in 'right' query function