helper function for token extraction
add database functions