Fix bugs related to visibility change.