Cleanup and Refactoring

Major refactoring and commenting of all the code. Any non-used
components have been removed.