now writing files properly