Improved error handling and namespace initialisation