more reliable way to open a file