Auth fix

Fixes the cancel button in Basic auth, tidies up code, removes some global variables.