did some cleanup and refactoring.