Fix assertion, small refactoring.