Added functionality to write into files