Commented and cleaned up

no functional changes, just commenting so it's easier to understand