Refactoring

Merging refactored code with Master