Implement sha1 for token. Refactor the code