Minor refactoring of jsonp callback code originally written by Tom van Oorschot <tomvanoorschot@gmail.com>