updating documentation
formatting code
major reorganization of logic structure -- has not been tested