sped up `replicate` function by 3x