improve test coverage and fix a couple bugs