Bug fixe and tests.