I have been using a similar script on a website I manage, but it needs an overhaul, maybe this is something you could bare in my mind for your script.
The main issue are words that need to stay in upper case. For example 'SQL' would need to be left alone. To get around this I just added a clause to the script that would ignore these single words, but I also found that phrases with these words were problematic, so I also had to add a section that would fix a phrase that contained the word that needed to be kept in upper case.
The number of words keep on growing, and the function keeps growing in size.
The solution I am looking for would use a table as an exclude list. It needs to be able to identify the excluded word in a phrase, not just as a single variable.