adding if else logic and newtab functionality