added mikes algorithm