porting to pure R - complete (?) for GBM