Redone for clearity
Also removed some redundant stuff.