added limit
added logic to prevent infinite looping
add ability to write to AWS s3