added loop end condition when last list element points at first list element