Add initial state (opened file) to History

Also some basic optimizations to use less memory.