added write to file functionality