Refactor with and with_ifempty