corrected function