Cleaning up some code for efficiency (in editing and performance)

Changed how the regex expressions are assembled. Moved link replacing into a function. Moved/changed/added several variables and comments for clarity.
Merge pull request #2 from SnoringFrog/patch-2

Cleaning up some code for efficiency (in editing and performance)