working implementation for stitch_map