Fixed key generation "bug"