Added in-line comments and fixed a potential issue on saving to file (regarding buffer overflow)