a little more code tidying and optimisation