Add tests, some fixes