Training now uses the database.  Also tidied up redundant code.