Code refactoring/streamlining and File IO functionality

Combination of Sean/Hugh and Nick's work.