brief tidying up of code and commenting