Fixed regex, documented a little, removed a global variable.