Refactoring

Optimisation code