Fixed error code being returned not accuractly