Fix a few things, extend test coverage