Added null/empty checks around namespace adding