Refactored Code from master