added delete function, it contains a logic error