refactoring and commenting for my own sanity. The class is too big to handle should break it