Create main algorithm