Fix duplicated blocks of code