Fixed a number of bugs in the builder code.  Cleaned up and refactored as well.