Minor re-factoring and bug-fixes.