start main algorithm implementation