neatened up code with writeNav