Abstracted code to make it a bit more readable

First, great work! :+1: 

Being new(er) to JS, it was very difficult to immediately understand what the code was doing. I was determined to understand what it did. This is my result of abstracting it away. Hopefully, it helps in some way.