Cleaned up key generation