Added pthreading and read/write functions