Fixed a reference mistake that caused an infinite loop, added a cycle check to break the loop if a previously encountered module is found again