Rewrote setData and added some comments

Made setData safer in case of an I/O failure. It also tries to recover after an item->setData(value, role) failure.

Added some other comments to make code more readable.