Add test case for circular dependencies within simulation function. Resolve dependeicies using new algorithm to avoid stack overflows.