refactor, optimisation, proper eventing