updated file manipulation code