Switch to a more idiomatic approach to replacing string parts, though this still has room for improvement.