Finished algorithm