Fixed issue with wrong namespace

CHG: various styling tweaks
CHG: code cleanup and refactoring
FIX: now honours ns correctly