added timing and fixed fwrite