Cleaned up the codebase and added in error reporting