Adding algorithm