Fixed duplicate code bug