replaced duplicate code