Access token database

Refactored the code according to the comments and added test cases.