refactor for issue #3659 by reordering methods have similar logic as closer to themselves