Rewrite everything.

This is a complete rewrite of iimux. It's a bit more maintainable now.