Refactored to ensure good component integration and refactored out reuse...

...d code