rearrange function declarations within automatch function so it works in Chrome extension and remove trailing whitespace