fix race condition and opacity bug