Major Refactoring

* Major refactoring of source code to externalize most components
* Cleaned up source code to add messages and remove unnesessary calls and unused functions