Move helper functions from tests to source / public API