fixed index out of bound error for step5a