refactored js code for loading s3 buckets