State logic added.