additional changes to the main algorithm