Refactor of the commands code (removing duplicated code)

Typo: "token", not "tokken". Also, please add a phpdoc block before method.