s3 code improvement