Tidied up code, debug & comments

This is v1.00.