Close #605. reduce some duplication

[skip ci]