Access token database

Refactored the code according to the comments and added test cases.
This iterative lookup in the dictionary defeats the purpose of using a dictionary in the first place.