I think this sorts out authentication, again needs ALOT of tidying up