Remove race condition in clock switching