TEST: increase test coverage

And fix a few bugs and remove redundant code