Code refactor. Remove duplicated code.