Code Refactor

Huge refactor for parsing, some API changes and some fixes to reading/writing files.