added more improvement, checks for strings that end with / and removes the last slash