more code improvements, and some regression fixes from yesterday's memory refactoring.