Improve getNext method