Refactoring

Legacy code has been refactored.