minor changes in main algorithm