fixed code so that works for both training and testing set