Fixed error code return bug