reduction of code reusing in one function