Add a few tests and some fixes