Remove unnecessary data check and tighten variable scope