first working implementation of gather