Refactor s3-related procs