repro code for issues 507, 508 and 509