More stable version with unit tests.