Update getUnvisitedElements implementation