on the way to finish, added algo realization, not tested.