rbm.train - refactored