Adding check for self-loops and cyclic dependencies while dependency creation