Changes: code optimisation and re-organisation.