Fix duplication of code