corrected  funciton