More test coverage, bug fixes