File write support - you can now write files!

- Added write support
- Fixed a crash when freeing some memory on exit