refactored to make training and testing obvious