Source code refactoring. Extracted common functionality into merged methods

Source code refactoring. Extracted common functionality into merged methods
Google C++ Style Guide forbids the use of tab. Code should be indented using spaces.