extracted code for insert cases of + and *