Code tidied up: debug code removed, necessary explanations added.