Fixed bug in file opening