some small important changes + cosmetic changes. Algorithm now working well