Restructed JS callbacks to work with oauth in a popup.