first working implementation of the algorithm in a mapper