Functions used in tests moved to misc.h/.cpp