Fixed substr bug