Refactor to get rid of circular dependency hack