Refactored. Changed to use class with smaller methods.