fix bug that can cause a crash