Move misc code into internal.h, cleanup