XD-166 refactored the original PR #39