Major rewrite, now training is also possible.
Major rewrite.