Improve previous/next detection