refactor aes method