algorithm does not work properly yet