fix DOM insertions and add case for empty fields