DG: splitted code up