Improvements: 1. Prepend magic number to file at the beginning 2. Open (and close) file only once 3. Some documentation