Lots of miscellaneous fixes to #defines, error checking, etc. Most importantly: IM-->REG works, aaah :D. Still lots of error checking to do/improve and lots of debug messages to clean.