This seems to fix the substring error.