Fixed a circular dependency bug and tests