Move detection code to the initialization method.