Some bug fixes on open_file