Refactoring of s3-handler.