Fixed an error in the next method and added prev