Move encryption code to method