added caching function to generate ids