Check token signature and refactoring