Refactoring code.

- Moving duplicated code into private method.