the implementation (with tests)