bug in algorithm

please check folder BUGs for details