Optimize select all function