[[ Clean up ]] Factor out some duplicated code