More tests and fix uncovered errors.