Add support for training and 2 segfault fixes