code backup
working, but pretty slow...
single out common code