Fix errors and update trainer script