simplify comparison function and more
imrpovements to populate_if_empty method