added comments and basic formatting