made openfile func to associate with files depending on mode