fix Having and tests added
code simplification
partially BC fixes