improve code coverage and fix some bugs