Test cases for #521 and #542