These preceeding str_replaces will always be applied to the remaining buffer.. Seems unneeded? Maybe there's a better approach?