fix regressions, add tests