Minor code tweaks and additional comments.
@fblundun - please review and then rebase if you are happy with the changes.