Debug Refactor

Added various chunks of debugging and error checking code, along with some high-level refactoring, e.g. namespaces, folder locations, etc.