cleaned up + wrote buffer