Refactored ready for CloudFront handling too