Previous and next Code refactored