Major cleanup and debug
Fix broken functions
Fix incorrect paramater references
Test Working modules
Add and clarify debug statements and comments