Changed delete function to accept a parmaeter instead of depending on a global variable.