Remove duplicate code and fix typo in comment