Fixed the AES bug again in another way which is hopefully more robust