Fixed the error handlin