Moved the asynchronous generation of keys to a separate class.