fixes: https://github.com/espressif/arduino-esp32/issues/55
many possible problems fixed in preparation for thread-safe