Added refresh tokens.

Also changed the way the "loadstart" event is handled.
Also removed unused code.