doxygen comments corrected, added checks of return values of write function