Tidy up validation of code and token