Fixed duplicate blocks of code