Code clean, more attempts to make it work.

Removed some unused code, more edits to the file writing to hopefully
get it working.