algorithm corrected