Add various write functions
Logging debug information to SD card, some fixes