Issue #012: Now handles end conditions.