Start refactorization of Gennady's code.