Added error handling to the c-Extension