Check return values and optimize zero checking