Refactor node code