Changes: code optimisation and bug-fixes.