finishing algorithm