fixed previous/next logic