Fix off by one error. Second parameter of substring is exclusive. (Note second substring below is correct since length() doesn't correspond to last index.)