Refactore the code. Extracted similar code.