algorithm not quite working, but plotting in place