fix a bug
numerous minor fixes.