Refactored a lot of file-handling code, added an error class and added additional confirmation messaging.