Factored out helper functions