Solve issue #138. Add tests.