fixing substr bug