Tidied up code for creating nodes