Use endsWith instead of cryptic substr