moved write2file call up a level