Refactoring
Merging alistair's work