CRAFTERCMS-818

Added code to protect against falling into infinite loop when having circular dependencies