Simplified the generation of the client id
Added storing and checking of state