added training functionality, it almost works