start working on the main algorithm