Add delete function and fix few bugs