consolidate and simplify (renamed) utility functions, with tests