Refactor code as suggested by Thomas Hisch

Below is the original comment:
https://github.com/sympy/csympy/pull/332#discussion_r20773992