some helper functions to deduplicate code