Added write and read file functions