Added changes for checking conditions before adding tuple