added replicateOnce and replicateM functions