Refactored to ensure good component integration and refactored out reused code