Added a couple of unit tests, fixed a crash.