half-working incremental algorithm