fixed lots of bugs and coordination of training and testing