getlantern/lantern#1762 Suggested improvements to original fix

@myleshorton Suggestions from my review of your changes
Moved to bottom of source file for readability.