added conditional to prev/next fn