Refactoring

Caveat - not tested