prepared step2.R for first tests (old code, reindented, all in one file)