fixed errors in file opening

fixed error in main program that caused the content of opened files to
be added to the tex box, rather than replacing the current content, and
another error which added a blank line to the bottom of the file when
opening it