added comments explaining function