Improved error handling and attribute test