Made formatting slightly more consistent; Moved map() call out of loop for performance reasons.