Tidy up javascript OAuth code