cleaner implementation of optimisation, with plugin possibilities