Fixed a leaked intent issue and made some other minor changes.

Please test it out and merge!