Fix bug that caused code duplication