Add reference key back and fix key generation.