refactored code to reduce instructions significantly for compiling test and training data sets