Add more assertions and rename some variables consistently.