fix cyclic references
add tests