Refactor in s3-api codes