Refactoring and switched to FileSaver.js for download