fixing toggle button timing issue