replace length calls with a comparison