Fix some problems and add some tests.