Code Cleanup

A whole lot of changes to the code base, should result in much cleaner and workable code.