added file logging, removed memory corruption bugs