Refactored redundant code.

Refactored redundant code.