Move common functionality into lib/nice-s3.js