Make close methods synchronized, to ensure close does not get called in the middle of a write