New code set-out

Code is set out clearer and comments are slightly simplified.