added logging, split up token generation