folder redirection: made changes to read/write routines to avoid race conditions