add file mode argument
use openFile function
modify call to openfile with mode argument