refactor previous optimisation