Algorithm work, debug improvments