Merge pull request #2628 from WalterBright/refactor-elem_print

refactor duplicate code from elem_print