Bug fixes and stat file

Outputs stats to a file upon completion