I cleaned it up some and removed a helper function. Hope it's more clear now.