progress on algo, but with bugs