fix slice out of bounds bug