Since we are using this on two screens, this should be a global function instead of being repeated here.