Added functionality for next and previous buttons