Improve formatting of replace function