refactor to extract common logic for moving the node to front.