handle empty elements correctly