added pretrain argument
refactoring