Use commons' substring function to avoid IndexOutOfBoundsExceptions.