added comments so that my spagetti code can be more easily understood