handle large datasets better
apply to replace loop