neaten up and comment code