Issues/fix 2 3 5 related issue

small refactoring and code clean up