More hacks and tweaks.

This needs to be cleaned up some day.