Cleanup S3 connection code
Code reorganization