Updated helper function