Main

First version of the main algorithm implemented