validation handling, some refactor of trainer