Fix stages. Add tests.