Modularize get_tokens, add function documentation