Compressed code by combining functions with similar resposibilities. Also added a call to remove row contents when the '__details_add' detected a row already exists (otherwise memory leak would occur).