Fix up algorithm