finalize training section: put database locks where needed, solve some TODO
small fixes