refactored to explain the code more clearly. Moved some logic into new classes and did renaming.