Optimised square method, and general tidying