Add tests and fix errors founded by them