Minor refactoring plus an extra assert and some comments.