Fixed problems with RegEx and re-formatted some code.