Refactor to update the maze directly when pushing or poping a node.