Getting off-topic is easy. The students are following you down a path towards a group of objectives and an ultimate goal. Your mind needs to be split into several parts during the teaching process. One part on you, one on the group as a whole, and one rotating from student to student. Asking questions of individual students keeps them on their toes and allows for continual review. When you go off track a bit, re-focus the group with questions.