A bit of refactoring and fix related to the recent change.
A few modifications and fixes.