Only close <ul> tag if it was opened.