Added proper error reporting