Fix slice out of bounds error