single function for creation and comparision