Fix errors + improvements on bug #683 fix.