improve object toggle function