Reworked the FileStreamWriter class to make it less error-prone.