fixed a bug in substr handling