Fixing bugs around cycle calculation