more refactoring and documenting

this is about as clean and refactored as I'm going to get it for now.