tests for #539
tests for #539
simplify code
fix #539