Adding algorithm for NIL