function now takes array as argument, sorting is done only if new values were added