fixed various regressions with gates logic