Using an expanded function for the token generator from http://stackoverflow.com/a/13733588.