fix slice out of bound error