Some clean-up and optimisation/generalization of systems, started on adding in-script documentation.