Add tests and small fixes