Code optimisation Pull request #143