Some code cleanup and bug fixes.