Improved code to remove loop to reduce number of calls to AES