Added in comments and minor tweaking based on suggestions from Idea