finished main algorithm
Revert "finished main algorithm"

This reverts commit 2a29d36bbdf438ae6460e5fcb6fe5ed769bea9ef.
finished main algorithm