Refactored get_next