slightly improve performance by checking ranges directly rather than creating a substring
some more improvements