Fixing Build Errors, and Refactoring