improve grid replicator, fix some corner cases