cleaned up imports and added write to file