move stuff that can be shared with c version up