cleanup code, move s3 object outside of functions