huge code refactoring for replacing old code with new one