Issue1808

refactoring and some fixing