modifyed algorithm. should work first try. as soonas i fix the bugs!!