Replace call to isEmpty() with a check on length()