simple clone of the simple implementation with some refactorings