Cleaned up and refactored code.  Some parts still need to be configured.