implemented writing to file