Access token database

Refactored the code according to the comments and added test cases.
Really not sure what is the point of this method as well.