Updated next and prev functions