Check Error type and remove Unused code