Various updates, cleanup

Earlier this year I made a few simple cleanups to the code but never bothered to make a pull request. They should merge fine with the google analytics stuff I think.
Could be good to include a comment here about why you're creating a MouseEvent. Is it to get around the popup blocker?