corrected implementation