Some more fixes and code cleanups.