Several necessary bug fixes.