relocate some common functions and types