improved speed by changing the IO operations position