Added a function endsWith so that the code is more readable