More build fixing and refactoring.