refactoring of aes wrapper code