added new logic and code for s3 integration