Refactoring code with extract to constructor