Updated for better error messages