Added checks for error conditions