refactor duplicate code from elem_print

refactor backend only, should not affect operation