work on total algorithm