represent nodes as integers, refactor code