Adding algorithm code