Use replace instead of loop, per Malikari's suggestion