Fix duplicated code