Training code completed and minor refactoring.