Added more checks, and fixed module inclusion circularity.