Corrected code to work with jQuery's borked deferred model.