fix for 2.5 compatibility and other corrections
ok
rename expand_flat to expand_poly