Refactored getNext