Fixed debugs, added proper exceptions

Also sorted the example files.

Improved the modio_writing test script.