extend test coverage and fix bug