CRAFTERCMS-818
Added code to protect against falling into infinite loop when having circular dependencies
Merge pull request #223 from dejan-brkic/master

CRAFTERCMS-818