Refactor code. Remove duplicated code.