Fix chop trailing whietspace

Also bit of a tidy up and add comments