have a working algorithm